package cn.mw.cmdb.virtualization.dto;

import cn.mw.cmdb.entity.InstanceInfo;
import cn.mw.cmdb.virtualization.constant.MwVirtualizationConstant;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author gengjb
 * @description 虚拟化树结构DTO
 * @date 2024/6/7 16:43
 */
@Getter
@Setter
@Schema(name = "VirtualizationTreeDto", description = "虚拟化树结构DTO")
public class VirtualizationTreeDto implements Serializable {

    private static final long serialVersionUID = 1L;

    @Schema(description = "数据信息")
    private VirtualizationTreeDataDto treeDataDto;

    @Schema(description = "下属数据")
    private List<VirtualizationTreeDto> children;

    @Schema(description = "主机ID集合")
    private List<String> instanceIds;

    @Schema(description = "ID")
    private String id;

    @Schema(description = "父ID")
    private String pid;

    @Schema(description = "名称")
    private String name;

    @Schema(description = "主机ID")
    private String hostId;

    @Schema(description = "实例ID")
    private String instanceId;

    @Schema(description = "虚拟类型")
    private String vmType;

    @Schema(description = "引擎ID")
    private String engineId;

    @Schema(description = "数量")
    private Integer count;

    @Schema(description = "基本信息数据")
    private List basicInfoData;

    public VirtualizationTreeDto(VirtualizationTreeDataDto treeDataDto) {
        this.treeDataDto = treeDataDto;
        this.children = new ArrayList<>();
        if(this.instanceIds == null){
            this.instanceIds = new ArrayList<>();
        }
        this.instanceIds.add(treeDataDto.getInstanceId());
    }

    public void addChild(VirtualizationTreeDto child) {
        this.children.add(child);
        this.instanceIds.addAll(child.getInstanceIds());
    }

    public void extractFrom(VirtualizationTreeDataDto node){
        this.id = node.getId();
        this.pid = node.getPid();
        this.name = node.getName();
        this.hostId = node.getHostId();
        this.instanceId = node.getInstanceId();
        this.vmType = node.getVmType();
        this.engineId = node.getEngineId();
        this.count = node.getCount();
    }
}
